/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Schedules {

    public static boolean insertSchedule(Entity.Schedule chs) {
        try {
            String sql = "insert into tblSchedule values(?,?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, chs.get_ClassID());
            ps.setString(2, chs.get_CoursesID());
            ps.setString(3, chs.get_UserID());
            ps.setString(4, chs.get_StartDate());
            ps.setString(5, chs.get_EndDate());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Schedules.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static boolean updateSchedule(Entity.Schedule chs) {
        try {
            String sql = "update tblSchedule set ClassID=?, CoursesID=?, UserID=?, StartDate=?, EndDate=? where ScheduleID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, chs.get_ClassID());
            ps.setString(2, chs.get_CoursesID());
            ps.setString(3, chs.get_UserID());
            ps.setString(4, chs.get_StartDate());
            ps.setString(5, chs.get_EndDate());
            ps.setInt(6, chs.get_ScheduleID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Schedules.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static void deleteSchedule(int intScheduleID) {
        try {
            String sql = "delete from tblSchedule where ScheduleID = " + intScheduleID;
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Schedules.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
